﻿<?php
if(!defined("IN_PHPSCUP"))exit("hacking");

class Ewebeditor
{

  var   $skinPath = "/data/ewebeditor/skins/default/";//皮肤路径
           
  var   $jsPath = "/data/ewebeditor/KindEditor.js";//kindeditor路径
  
  var   $iconPath = "/data/ewebeditor/faceicon/";//表情路径
  
  var   $imageAttachPath = "upfiles";//文件上传存放路径
  
  var   $imageUploadCgi = "";//文件上传处理路径
  
  var   $cssPath = "/data/ewebeditor/common.css";//css路径
  
  var   $editorWidth = "100%";//编辑器的宽度 
  
  var   $parentID = "";//编辑器父类的id 号
  
  var   $flvplayerpath = "";//flv播放器的位置
  
 function __construct($config = array())
    {	
	
        $this->Ewebeditor($config);
				
    }
	   
 function Ewebeditor($config = array())
    {	
	    if(!isset($config['skinPath']))
		{
		   $config['skinPath']="";
		}	
	    if(!isset($config['jsPath']))
		{
		   $config['jsPath']="";
		}	
	    if(!isset($config['iconPath']))
		{
		   $config['iconPath']="";
		}	
		
	    if(!isset($config['imageAttachPath']))
		{
		  $config['imageAttachPath'] ="";
		}			
		
	    if(!isset($config['imageUploadCgi']))
		{
		  $config['imageUploadCgi'] ="";
		}			
		
	    if(!isset($config['cssPath']))
		{
		   $config['cssPath']="";
		}			

	    if(!isset($config['editorWidth']))
		{
		  $config['editorWidth'] ="";
		}	

	    if(!isset($config['flvplayerpath']))
		{
		   $config['flvplayerpath']="";
		}	

		

        $this->skinPath = !empty($config['skinPath'])?$config['skinPath']:SITE_URL . "/data/ewebeditor/skins/default/";//皮肤路径
           
        $this->jsPath = !empty($config['jsPath'])?$config['jsPath']:SITE_URL . "/data/ewebeditor/KindEditor.js";//kindeditor路径
  
        $this->iconPath = !empty($config['iconPath'])?$config['iconPath']:SITE_URL . "/data/ewebeditor/faceicon/";//表情路径
  
        $this->imageAttachPath = !empty($config['imageAttachPath'])?$config['imageAttachPath']:"upfiles";//文件上传存放路径
  
        $this->imageUploadCgi = !empty($config['imageUploadCgi'])?$config['imageUploadCgi']:"";//文件上传处理路径
  
        $this->cssPath = !empty($config['cssPath'])?$config['cssPath']:SITE_URL . "/data/ewebeditor/common.css";//css路径
  
        $this->editorWidth = !empty($config['editorWidth'])?$config['editorWidth']:"100%";//编辑器的宽度
		 
        $this->flvplayerpath = !empty($config['flvplayerpath'])?$config['flvplayerpath']:SITE_URL . "/data/ewebeditor/images/player.swf";
	
	}


 function upfile($upfilepath = 'tmp')
    {
		

if(!isset($_GET['Ctype']))
{
$_GET['Ctype']='';
}	
if(!isset($_POST['fileData']))
{
$_POST['fileData']='';
}		
if(!isset($_POST['imgWidth']))
{
$_POST['imgWidth']='';
}	  
if(!isset($_POST['imgHeight']))
{
$_POST['imgHeight']='';
}			   	   		   
if(!isset($_POST['imgBorder']))
{
$_POST['imgBorder']='';
}
if(!isset($_POST['imgTitle']))
{
$_POST['imgTitle']='';
}
if(!isset($_POST['imgAlign']))
{
$_POST['imgAlign']='';
}
if(!isset($_POST['imgHspace']))
{
$_POST['imgHspace']='';
}
if(!isset($_POST['imgVspace']))
{
$_POST['imgVspace']='';
}
if(!isset($user_name))
{
$user_name='';
}  
		   $Ctype = $_GET['Ctype'];
		   		   
           $fileData = $_POST['fileData'];
		   
		   $imgWidth = $_POST['imgWidth'];
		   
		   $imgHeight = $_POST['imgHeight'];
		   $imgBorder = $_POST['imgBorder'];
		   $imgTitle = $_POST['imgTitle'];
		   $imgAlign = $_POST['imgAlign'];
		   $imgHspace = $_POST['imgHspace'];
		   $imgVspace = $_POST['imgVspace'];

           if(!$fileData)
		   {
		         if(!$Ctype)
				 {
				  $icon = true ;
				 }
				 else
				 {
				  $icon = false ;
				 }
		   
		   	     include(ROOT_PATH.'/lib/upfile.lib.php');	  
	             $upfile = new Upfile($upfilepath,$icon); 
				 
	             $upfile->_file_msg['user_name'] = $user_name;					 
				 
				 $upfile->_file_msg['name']=$_FILES['fileData']['name'];
			     $upfile->_file_msg['size']=$_FILES['fileData']['size'];
	 	  
	             $updata = $upfile->_upfile($_FILES['fileData']['tmp_name']);
				 $data['path'] = $updata['path'];	
				 $newfile = SITE_URL . '/' . UPFILE_PATH . '/' . $data['path'];
	
	
	              //插入数据，关闭层
	             echo '<html>';
	             echo '<head>';
	             echo '<title>Insert Image</title>';
	             echo '<meta http-equiv="content-type" content="text/html; charset='.VIEW_CHARSET.'">';
	             echo '</head>';
	             echo '<body>';

	             if(!$Ctype)
	             {
		         echo "<SCRIPT LANGUAGE=\"JavaScript\">parent.KindInsertImage('$newfile','$imgWidth','$imgHeight','$imgBorder','$imgTitle','$imgAlign','$imgHspace','$imgVspace')</SCRIPT>";
	             }
	             else
	             {
		         echo "<SCRIPT LANGUAGE=\"JavaScript\">parent.KindInsertImageP8FLV('$newfile','$imgWidth','$imgHeight','$Ctype')</SCRIPT>";
	             }
	             echo '</body>';
	             echo '</html>';
	              exit;
         }

	}

	
 function show()
    {	
		
      $this->parentID = $_GET['id'];
      $title = $GLOBALS['Lang']->_get_lang_var(SITE_TITLE); 
      $charset = VIEW_CHARSET;  
	  
print <<<EOT
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=$charset">
<title>$title</title>
</head>
<body leftmargin="0" topmargin="0">
<SCRIPT LANGUAGE="JavaScript">
<!--
var bokecc_id="";
//-->
 </SCRIPT>
<script type="text/javascript"  src="$this->jsPath"></script>
<input type="hidden" name="content" id="content">
<script type="text/javascript">
var editor = new KindEditor("editor");
editor.hiddenName = "content";
editor.skinPath = "$this->skinPath";

editor.iconPath = "$this->iconPath";
editor.imageAttachPath = "$this->imageAttachPath";
editor.imageUploadCgi = "$this->imageUploadCgi";
editor.cssPath = "$this->cssPath";
editor.editorWidth = "$this->editorWidth";
editor.parentID = "$this->parentID";
editor.flvplayerpath = "$this->flvplayerpath";
function get_height(){
	h=0;
	if(parent.document.getElementById("eWebEditor1")!=null){
		h=(parent.document.getElementById("eWebEditor1").height-60);
	}
	if(h<10){
		h=100;
	}
	return (h+'px');
}
function show_edit(){
	editor.editorHeight =get_height();
	editor.show();
}
setcode();
show_edit();

function setcode(){
	document.getElementById('content').value=parent.document.getElementById('$this->parentID').value;
}

document.onmousemove=editor.code;


function set_input(){
	editor.code();
	setTimeout("set_input()",30);
}
set_input();

</script>
 
</body>
</html>
EOT;

	    exit;	
	}
	
    //提示，关闭层
    function alert($msg)
   {
	    echo '<html>';
	    echo '<head>';
	    echo '<title>error</title>';
	    echo '<meta http-equiv="content-type" content="text/html; charset='.VIEW_CHARSET.'">';
	    echo '</head>';
	    echo '<body>';
	    echo '<script type="text/javascript">alert("'.$msg.'");parent.KindDisableMenu();parent.KindReloadIframe();</script>';
	    echo '</body>';
	    exit;	    echo '</html>';
	    exit;
   }	

}

?>